/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RecordatorioContrasena.java
 *
 * Created on 31/05/2011, 06:43:48 PM
 */
package gui;
import controlador.*;
import javax.swing.*;
import logica.*;

/**
 *
 * @author Gamboa Family
 */
public class RecordatorioContrasena extends javax.swing.JFrame {

    ControladorUsuario control = new ControladorUsuario();
    /** Creates new form RecordatorioContrasena */
    public RecordatorioContrasena() {
        initComponents();
        this.setTitle("Recordatorio de Contraseña");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTFLogin = new javax.swing.JTextField();
        jTFRespuestas = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jCBPregSecreta1 = new javax.swing.JComboBox();
        jBRecordar = new javax.swing.JButton();
        jBFinalizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 20)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(235, 30, 30));
        jLabel1.setText("Recordatorio de Contraseña");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(235, 30, 30)));

        jLabel3.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(130, 134, 135));
        jLabel3.setText("Pregunta Secreta");

        jLabel4.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(130, 134, 135));
        jLabel4.setText("Respuesta Secreta");

        jTFLogin.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N

        jTFRespuestas.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
        jTFRespuestas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTFRespuestasActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(130, 134, 135));
        jLabel2.setText("Login");

        jCBPregSecreta1.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
        jCBPregSecreta1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Escoja:", "¿Como se llama su mascota?", "¿Cual es su escritor favorito?", "¿A que jardin infantil asistio usted?", "¿Cual es su lugar favorito?", "¿Donde nacio su madre?", "¿Cual es su color favorito?", "¿Como se llama su mascota?", "¿Cual es su escritor favorito?", "¿A que jardin infantil asistio usted?", "¿Cual es su lugar favorito?", "¿Donde nacio su madre?", "¿Cual es su color favorito?" }));

        jBRecordar.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jBRecordar.setForeground(new java.awt.Color(235, 30, 30));
        jBRecordar.setText("Recordar");
        jBRecordar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRecordarActionPerformed(evt);
            }
        });

        jBFinalizar.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jBFinalizar.setForeground(new java.awt.Color(235, 30, 30));
        jBFinalizar.setText("Finalizar");
        jBFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBFinalizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jBRecordar)
                        .addGap(18, 18, 18)
                        .addComponent(jBFinalizar))
                    .addComponent(jTFRespuestas, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                    .addComponent(jCBPregSecreta1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTFLogin))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTFLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jCBPregSecreta1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTFRespuestas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBRecordar)
                    .addComponent(jBFinalizar))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(69, 69, 69))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTFRespuestasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFRespuestasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTFRespuestasActionPerformed

    private void jBRecordarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRecordarActionPerformed
        // TODO add your handling code here:
        boolean completo = true;
        String pregunta = String.valueOf(jCBPregSecreta1.getSelectedItem());

        String mensaje = "Hay errores en la modificación de su Perfil:     " + "\n\n";
        if(jTFLogin.getText().equals("")){
            completo = false;
            mensaje += "-> El campo Login está vacío." + "\n";
        }
        if(completo && !control.existeLogin(jTFLogin.getText())){
            completo = false;
            mensaje += "-> El login ingresado no está registrado en el sistema." + "\n";
        }
        if(jCBPregSecreta1.getSelectedIndex() == 0){
            completo = false;
            mensaje += "-> Debe escoger la pregunta secreta." + "\n";
        }
        if(jTFRespuestas.getText().equals("")){
            completo = false;
            mensaje += "-> El campo Respuesta Secreta está vacío." + "\n";
        }

        String codigo = control.getCodigo(jTFLogin.getText());
        Usuario usuario = control.retornarUsuarioPorCodigo(codigo);

        if(completo && !jTFRespuestas.equals(usuario.getRespuestaSecreta())){
            completo = false;
            mensaje += "-> El respuesta es incorrecta." + "\n";
        }
        if(completo) {
            JOptionPane.showMessageDialog(null,"La Contrasena es: "+usuario.getContrasena());
            jTFLogin.setText("");
            jTFRespuestas.setText("");
            jCBPregSecreta1.setSelectedIndex(0);
        } else
            JOptionPane.showMessageDialog(this, mensaje, "Error",
                    JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_jBRecordarActionPerformed

    private void jBFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBFinalizarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBFinalizarActionPerformed

    /**
     * @param args the command line arguments
     */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RecordatorioContrasena().setVisible(true);
            }
        });
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBFinalizar;
    private javax.swing.JButton jBRecordar;
    private javax.swing.JComboBox jCBPregSecreta1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTFLogin;
    private javax.swing.JTextField jTFRespuestas;
    // End of variables declaration//GEN-END:variables
}
